package cn.itcast.activiti.servlet.deployment;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.apache.catalina.connector.Request;

import cn.itcast.activiti.common.ProcessEngineUtils;
/**
 * 查询流程定义
 * @author LEE.SIU.WAH
 * @email lixiaohua7@163.com
 * @date 2016年5月6日 下午2:43:15
 * @version 1.0
 */
@WebServlet("/queryProcessDefinition.action")
public class QueryProcessDefinitionServlet extends HttpServlet{

	private static final long serialVersionUID = -2560718776750220202L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/** 获取流程引擎 */
		ProcessEngine pe=ProcessEngineUtils.getProcessEngine();
		/** 获取仓储服务 */
		RepositoryService rs=pe.getRepositoryService();
		/** 创建流程定义查询对象 */
		ProcessDefinitionQuery pdq=rs.createProcessDefinitionQuery();
		/** 按最终版本获取所有的流程定义 */
		List<ProcessDefinition> pdLists=pdq.latestVersion().list();
		
		request.setAttribute("pdLists", pdLists);
		request.getRequestDispatcher("/processDefinition.jsp").forward(request, response);;
	}
	
	

}
